<template>
  <div class="news-column">
    <h3>最近热门活动</h3>
    <div class="activity-list">
      <div v-for="activity in activities" :key="activity.id" class="activity-item">
        <div class="activity-info">
          <p class="activity-description">{{ truncate(activity.description, 30) }}</p>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
// 模拟活动数据
const activities = [
  {
    id: 1,
    name: '编程大赛',
    description: '这是一场激烈的编程竞赛，展示学生们的编程技能。'
  },
  {
    id: 2,
    name: '音乐会',
    description: '音乐社团将举办一场精彩的音乐会，欢迎大家参加。'
  },
  {
    id: 3,
    name: '篮球比赛',
    description: '篮球协会将举行一场友谊赛，展示团队合作精神。'
  }
]

// 截断字符串函数
const truncate = (str, maxLength) => {
  if (!str) return '';
  if (str.length <= maxLength) return str;
  return str.substring(0, maxLength) + '...';
}
</script>
<style scoped>
.news-column {
  width: 36%;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  background-color: rgb(236, 245, 255);
  border-radius: 8px;
}

.activity-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.activity-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #e8e8e8;
}

.activity-info {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
}

.activity-name {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
}

.activity-description {
  font-size: 14px;
  line-height: 1.5;
  color: #666;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>